# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.exceptions import ValidationError

class EmpOvertimedetail(models.Model):

    _name = 'emp.overtimedetail'
    overtime_id = fields.Many2one(string='加班申請單',comodel_name='emp.overtime')

    pautono = fields.Many2one(string='人員電腦編號',comodel_name='emp.peo')
    formno = fields.Char('補休單號')
    code = fields.Char('補休人員職員編號')
    cname = fields.Char('補休人員姓名')
    dep = fields.Char('補休人員單位')
    ptitle = fields.Char('補休人員職稱')
    year = fields.Char('補休人員單位')
    sess = fields.Char('學期')
    vstart = fields.Datetime('開始日期')
    vend = fields.Datetime('結束日期')
    vdays = fields.Char('可休天數')
    vhours = fields.Char('可休時數')
    edays = fields.Char('已休天數')
    ehours = fields.Char('已休時數')
    thours = fields.Char('已休時數')
    yn = fields.Char('是否允許補休')
    created = fields.Char('申請日期')
    applyname = fields.Char('申請人姓名')
    applyno = fields.Char('申請人帳號')
    state = fields.Char('單據狀態')
    sign_status = fields.Char('簽核狀態(顯示)')
    status = fields.Char('簽核狀態(代碼)')
    effectdate = fields.Datetime('生效日期')
    reason = fields.Text('補休事由')
    expire_date = fields.Datetime('有效日期')
    depno = fields.Char('部門編號')
    depkind = fields.Char('此部門是行政單位還是教學單位')
    deplevel = fields.Char('請假人單位為一級或二級')
    adminiunit = fields.Char('主要單位')
    adminRemark = fields.Char('')
    applytype = fields.Char('')

    @api.onchange('overtime_id')
    def name_not_null(self):
        if self.overtime_id:
            self.created = self.overtime_id.created
            self.vstart = self.overtime_id.vstart
            self.vend = self.overtime_id.vend
            self.expire_date = self.overtime_id.expire_date

    @api.onchange('pautono')
    def set_cname(self):
        if self.pautono:
            self.cname = self.pautono.cname